package oc_routers

import (
	"fmt"
	"log"
	"oc_saas/docs"
	_ "oc_saas/docs"
	route_admin "oc_saas/internal/app/route/admin"
	route_test "oc_saas/internal/app/route/test"
	"oc_saas/internal/glo"
	base_middleware "oc_saas/internal/middleware/base" // swagger embed files

	"github.com/gin-gonic/gin"
	swaggerFiles "github.com/swaggo/files"
	ginSwagger "github.com/swaggo/gin-swagger"
)

func Router() {
	gin.ForceConsoleColor()
	r := gin.New()
	r.GET("/swagger/*any", ginSwagger.WrapHandler(swaggerFiles.Handler))
	{
		r.Use(gin.Logger())
		r.Use(base_middleware.CustomRecovery())
	}
	nr := r.Group(glo.OC_CONF.Server.Prefix)
	{
		route_test.RouteGroup.InitRouteGroup(nr)
	}
	v1 := nr.Group(glo.OC_CONF.Server.Version)
	{
		route_admin.RouteGroup.InitRouteGroup(v1)
	}
	docs.SwaggerInfo.BasePath = glo.OC_CONF.Server.Prefix

	var port = fmt.Sprintf(":%v", glo.OC_CONF.Server.Port)
	if err := r.Run(port); err != nil {
		log.Fatal(err, "路由初始化失败")
	}
	fmt.Println("路由初始化成功:", glo.OC_CONF.Server.Port)
}
